/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.baseInfo.AnnotationInfo;
import com.inspur.edp.caf.generator.baseInfo.AnnotationType;
import com.inspur.edp.caf.generator.item.InterfaceGenerator;
import com.inspur.edp.caf.generator.item.InterfaceGeneratorContext;
import com.inspur.edp.cef.api.attr.I18nResourceAttribute;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.apiGenerator.CefApiGeneratorContext;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.dataTypeInfo.DataTypeInfoGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.resourceInfo.DataTypeResourceInfoGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.resourceInfo.EntityResourceInfoGenerator;
import com.inspur.edp.cef.generator.overall.Utils;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.TypeLiteral;

public abstract class DataTypeInterfaceGenerator extends InterfaceGenerator {
    private CefApiGeneratorContext apiGenContext;
    private IGspCommonDataType dataType;

    protected DataTypeInterfaceGenerator(
            CefApiGeneratorContext apiGenContext, IGspCommonDataType dataType) {
        super(apiGenContext.getCompilationUnitInfo());
        this.apiGenContext = apiGenContext;
        this.dataType = dataType;
    }


    // keyword:
    // ORIGINAL LINE: protected new DataTypeInterfaceGeneratorContext getContext() { return
    // (DataTypeInterfaceGeneratorContext)super.getContext(); }
    @Override
    protected DataTypeInterfaceGeneratorContext getContext() {
        return (DataTypeInterfaceGeneratorContext) super.getContext();
    }

    @Override
    protected void beforeInitialize() {
        super.beforeInitialize();
        apiGenContext
                .getEntityInterfaceTypes()
                .put(dataType.getCode(), new MediateType(apiGenContext.getPackageName(), getName()));
    }

    @Override
    protected InterfaceGeneratorContext createInterfaceItemContext() {
        return createEntityInterfaceGenContext();
    }

    protected DataTypeInterfaceGeneratorContext createEntityInterfaceGenContext() {
        return new DataTypeInterfaceGeneratorContext(apiGenContext, dataType);
    }

    @Override
    protected java.util.ArrayList<ModifierKeyword> getAccessModifier() {
        ArrayList<ModifierKeyword> result = new java.util.ArrayList<ModifierKeyword>(1);
        result.add(ModifierKeyword.PUBLIC_KEYWORD);
        return result;
    }

//    @Override
//    protected java.util.ArrayList<AnnotationInfo> getAttributeList() {
//        ArrayList<AnnotationInfo> result = new ArrayList();
//        MediateType dataTypeInfoType = getContext().getDataTypeInfoType();
//        if(dataTypeInfoType != null) {
//            AnnotationInfo annotationInfo = new AnnotationInfo();
//            annotationInfo.setTypeInfo(Utils.createTypeInfo(I18nResourceAttribute.class));
//            annotationInfo.setAnnotationType(AnnotationType.Normal);
//            TypeLiteral typeLiteral = ast.newTypeLiteral();
//            typeLiteral.setType(
//                ast.newSimpleType(ast.newName(dataTypeInfoType.getClassName())));
//            HashMap<String, Expression> params = new HashMap<String, Expression>(1);
//            params.put("resourceInfoType", typeLiteral);
//            annotationInfo.setParams(params);
//            result.add(annotationInfo);
//        }
//        return result;
//    }

    @Override
    protected java.util.ArrayList<BaseGenerator> createChildGenerators() {
        ArrayList<BaseGenerator> list = super.createChildGenerators();
        if (list == null) {
            list = new java.util.ArrayList<BaseGenerator>();
        }
        // 节点
        DataTypeInfoGenerator dataTypeGen = createDataTypeInfoGenerator();
        if (dataTypeGen != null)
            list.add(dataTypeGen);
        DataTypeResourceInfoGenerator resourceInfo = createResourceInfoGenerator();
        if(resourceInfo != null)
        list.add(resourceInfo);

        return list;
    }

    //与DataTypeSingleInterfaceGenerator存在重复实现
    protected DataTypeInfoGenerator createDataTypeInfoGenerator() {
        return null;
    }

    //与DataTypeSingleInterfaceGenerator存在重复实现
    protected abstract DataTypeResourceInfoGenerator createResourceInfoGenerator();
}
